import java.util.Arrays;

/**
 * <pre>{@code
 * 矩阵工具类
 * }</pre>
 *
 * @author Summerday
 * @date 2023/3/5
 */
public class MatrixUtils {
    private MatrixUtils() {

    }

    public static double[][] zeros(int M, int N) {
        return new double[M][N];
    }

    public static double[][] ones(int M, int N) {
        double[][] res = new double[M][N];
        for(double[] x : res) {
            Arrays.fill(x, 1);
        }
        return res;
    }

    public static void show(double[][] x, int m, int n) {
        for(int i = 1; i <= m; i++) {
            for(int j = 1; j <= n; j++) {
                System.out.print(x[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }

    public static void show(double[] x, int n) {
        System.out.println(Arrays.toString(Arrays.copyOfRange(x, 1, n + 1)));
        System.out.println();
    }

    public static boolean equal(double[][] A, double[][] B) {
        if(A.length != B.length || A[0].length != B[0].length) {
            return false;
        }
        for(int i = 0; i < A.length; i++) {
            for(int j = 0; j < A[0].length; j++) {
                if(A[i][j] != B[i][j]) {
                    return false;
                }
            }
        }
        return true;
    }
}
